<template>
  <div class="message-container content-container">
    <!-- 页面头部 -->
    <header class="message-header">
      <h1>消息</h1>
      <button class="settings-btn">
        <i class="fa fa-cog"></i>
      </button>
    </header>

    <!-- 消息标签页 -->
    <div class="message-tabs">
      <button 
        v-for="tab in tabs" 
        :key="tab.id"
        class="tab-btn"
        :class="{ active: activeTab === tab.id }"
        @click="activeTab = tab.id"
      >
        {{ tab.name }}
        <span v-if="tab.badge" class="badge">{{ tab.badge }}</span>
      </button>
    </div>

    <!-- 消息内容区域 -->
    <div class="message-content content-wrapper">
      <!-- 互动消息 -->
      <div v-if="activeTab === 'interaction'" class="interaction-messages">
        <div v-for="(message, index) in interactionMessages" :key="index" class="message-item">
          <div class="message-avatar">
      <img v-img-error :src="message.avatar" :alt="message.username">
          </div>
          <div class="message-body">
            <div class="message-info">
              <span class="username">{{ message.username }}</span>
              <span class="action">{{ message.action }}</span>
            </div>
            <div class="message-content">
              {{ message.content }}
            </div>
            <div class="message-meta">
              <span class="time">{{ message.time }}</span>
              <button class="reply-btn">回复</button>
            </div>
          </div>
          <div v-if="message.image" class="message-image">
            <img :src="message.image" :alt="'相关图片'">
          </div>
        </div>

        <!-- 无消息提示 -->
        <div v-if="interactionMessages.length === 0" class="empty-message">
          <i class="fa fa-inbox"></i>
          <p>暂无互动消息</p>
        </div>
      </div>

      <!-- 系统通知 -->
      <div v-if="activeTab === 'notification'" class="notification-messages">
        <div v-for="(notification, index) in notifications" :key="index" class="notification-item" :class="{ unread: !notification.read }">
          <div class="notification-icon" :style="{ backgroundColor: notification.color }">
            <i :class="notification.icon"></i>
          </div>
          <div class="notification-body">
            <h3 class="notification-title">{{ notification.title }}</h3>
            <p class="notification-content">{{ notification.content }}</p>
            <span class="notification-time">{{ notification.time }}</span>
          </div>
        </div>

        <!-- 无通知提示 -->
        <div v-if="notifications.length === 0" class="empty-message">
          <i class="fa fa-bell-o"></i>
          <p>暂无系统通知</p>
        </div>
      </div>

      <!-- 私信聊天 -->
      <div v-if="activeTab === 'chat'" class="chat-messages">
        <div v-for="(chat, index) in chats" :key="index" class="chat-item" @click="openChat(chat.id)">
          <div class="chat-avatar">
      <img v-img-error :src="chat.avatar" :alt="chat.name">
            <span v-if="chat.online" class="online-indicator"></span>
          </div>
          <div class="chat-info">
            <div class="chat-header">
              <h3 class="chat-name">{{ chat.name }}</h3>
              <span class="chat-time">{{ chat.lastMessageTime }}</span>
            </div>
            <p class="last-message" :class="{ unread: chat.unreadCount > 0 }">
              {{ chat.lastMessage }}
            </p>
          </div>
          <div v-if="chat.unreadCount > 0" class="unread-badge">{{ chat.unreadCount }}</div>
        </div>

        <!-- 无聊天提示 -->
        <div v-if="chats.length === 0" class="empty-message">
          <i class="fa fa-comments-o"></i>
          <p>暂无聊天消息</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'MessageView',
  data() {
    return {
      // 标签页数据
      tabs: [
        { id: 'interaction', name: '互动消息', badge: 5 },
        { id: 'notification', name: '系统通知', badge: 3 },
        { id: 'chat', name: '私信', badge: 8 },
      ],
      activeTab: 'interaction',
      // 互动消息数据
      interactionMessages: [
        {
          id: 1,
          username: '动漫爱好者',
          avatar: '/src/assets/周杰伦.png',
          action: '赞了你的视频',
          content: '黑神话悟空最新实机演示分析',
          image: '@/assets/黑神话.jpeg',
          time: '10分钟前',
        },
        {
          id: 2,
          username: '音乐达人',
          avatar: '/src/assets/悟空.jpg',
          action: '评论了你的动态',
          content: '这个音乐推荐太棒了，已经加入我的收藏！',
          time: '2小时前',
        },
        {
          id: 3,
          username: '游戏玩家',
          avatar: '/src/assets/黑悟空.jpg',
          action: '分享了你的直播',
          content: '技术流操作，学到了！',
          time: '昨天',
        },
        {
          id: 4,
          username: '美食家',
          avatar: '/src/assets/周杰伦.png',
          action: '关注了你',
          content: '',
          time: '3天前',
        },
        {
          id: 5,
          username: '科技迷',
          avatar: '/src/assets/悟空.jpg',
          action: '回复了你的评论',
          content: '确实如此，这款产品的性价比很高！',
          time: '上周',
        },
      ],
      // 系统通知数据
      notifications: [
        {
          id: 1,
          title: '账号安全提醒',
          content: '您的账号在新设备上登录，请确认是否为本人操作。',
          time: '30分钟前',
          read: false,
          icon: 'fa-shield',
          color: '#FF6B6B',
        },
        {
          id: 2,
          title: '活动通知',
          content: '二次元美食节活动已开始，立即参与赢取限定周边！',
          time: '今天 10:00',
          read: false,
          icon: 'fa-gift',
          color: '#4ECDC4',
        },
        {
          id: 3,
          title: '系统维护公告',
          content: '系统将于今晚23:00-次日01:00进行例行维护，期间部分功能可能暂时无法使用。',
          time: '昨天',
          read: false,
          icon: 'fa-cog',
          color: '#45B7D1',
        },
      ],
      // 私信聊天数据
      chats: [
        {
          id: 1,
          name: '小明',
          avatar: '/src/assets/周杰伦.png',
          lastMessage: '周末有什么计划吗？',
          lastMessageTime: '刚刚',
          unreadCount: 2,
          online: true,
        },
        {
          id: 2,
          name: '动漫社团',
          avatar: '/src/assets/悟空.jpg',
          lastMessage: '下周的社团活动通知已发布，请查收',
          lastMessageTime: '1小时前',
          unreadCount: 1,
          online: false,
        },
        {
          id: 3,
          name: '游戏好友',
          avatar: '/src/assets/黑悟空.jpg',
          lastMessage: '晚上一起组队打游戏吗？',
          lastMessageTime: '3小时前',
          unreadCount: 5,
          online: true,
        },
      ],
    }
  },
  methods: {
    openChat(chatId) {
      // 这里可以实现打开聊天详情页的逻辑
      console.log('打开聊天:', chatId)
    },
  },
}
</script>

<style scoped>
/* 消息页面容器 */
.message-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: 80px; /* 为底部导航留出空间 */
}

/* 页面头部 */
.message-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

.message-header h1 {
  font-size: 28px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.settings-btn {
  width: 40px;
  height: 40px;
  border: none;
  background-color: var(--hover-bg-color);
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-secondary);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-btn:hover {
  background-color: var(--primary-color);
  color: white;
  transform: scale(1.05);
}

/* 标签页样式 */
.message-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.message-tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  padding: 15px 25px;
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--text-secondary);
  cursor: pointer;
  position: relative;
  white-space: nowrap;
  transition: all 0.3s ease;
}

.tab-btn.active {
  color: var(--primary-color);
  font-weight: 600;
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 25%;
  width: 50%;
  height: 3px;
  background-color: var(--primary-color);
  border-radius: 3px;
}

.tab-btn:hover {
  color: var(--primary-color);
}

.badge {
  background-color: var(--primary-color);
  color: white;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
  min-width: 20px;
  text-align: center;
  display: inline-block;
}

/* 消息内容区域 */
.message-content {
  min-height: 400px;
}

/* 通用消息项样式 */
.message-item {
  display: flex;
  padding: 15px 0;
  border-bottom: 1px solid var(--border-color);
  transition: all 0.3s ease;
}

.message-item:hover {
  background-color: var(--hover-bg-color);
}

/* 互动消息样式 */
.message-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  overflow: hidden;
  margin-right: 15px;
  flex-shrink: 0;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-body {
  flex: 1;
  min-width: 0;
}

.message-info {
  margin-bottom: 8px;
}

.username {
  font-weight: 600;
  color: var(--text-primary);
  margin-right: 8px;
}

.action {
  color: var(--text-secondary);
  font-size: 14px;
}

.message-content {
  color: var(--text-primary);
  margin-bottom: 8px;
  font-size: 14px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.time {
  color: var(--text-secondary);
  font-size: 13px;
}

.reply-btn {
  padding: 4px 12px;
  background-color: transparent;
  border: 1px solid var(--primary-color);
  color: var(--primary-color);
  border-radius: 15px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.reply-btn:hover {
  background-color: var(--primary-color);
  color: white;
}

.message-image {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  overflow: hidden;
  margin-left: 15px;
  flex-shrink: 0;
}

.message-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 系统通知样式 */
.notification-item {
  display: flex;
  align-items: flex-start;
  padding: 15px;
  margin-bottom: 10px;
  background-color: var(--card-bg);
  border-radius: 12px;
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
}

.notification-item:hover {
  transform: translateX(5px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.notification-item.unread {
  border-left: 4px solid var(--primary-color);
  background-color: rgba(251, 114, 153, 0.05);
}

.notification-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
  margin-right: 15px;
  flex-shrink: 0;
}

.notification-body {
  flex: 1;
  min-width: 0;
}

.notification-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 5px;
}

.notification-content {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0 0 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notification-time {
  font-size: 13px;
  color: var(--text-secondary);
}

/* 私信聊天样式 */
.chat-item {
  display: flex;
  align-items: center;
  padding: 15px;
  margin-bottom: 10px;
  background-color: var(--card-bg);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
}

.chat-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
}

.chat-avatar {
  position: relative;
  width: 55px;
  height: 55px;
  border-radius: 50%;
  overflow: hidden;
  margin-right: 15px;
  flex-shrink: 0;
}

.chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.online-indicator {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background-color: #52C41A;
  border: 2px solid white;
  border-radius: 50%;
}

.chat-info {
  flex: 1;
  min-width: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.chat-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.chat-time {
  font-size: 13px;
  color: var(--text-secondary);
}

.last-message {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.last-message.unread {
  color: var(--text-primary);
  font-weight: 500;
}

.unread-badge {
  background-color: var(--primary-color);
  color: white;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
  margin-left: 10px;
  flex-shrink: 0;
}

/* 无消息提示 */
.empty-message {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-message i {
  font-size: 48px;
  margin-bottom: 15px;
  opacity: 0.5;
}

.empty-message p {
  font-size: 16px;
  margin: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .message-container {
    padding: 15px;
  }
  
  .message-header h1 {
    font-size: 24px;
  }
  
  .tab-btn {
    padding: 12px 20px;
    font-size: 15px;
  }
  
  .message-avatar,
  .chat-avatar {
    width: 45px;
    height: 45px;
  }
  
  .notification-icon {
    width: 35px;
    height: 35px;
    font-size: 16px;
  }
}
</style>